/***************************************************************************
 *   Copyright (C) 2005 by xihe   *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "ClusterInfoReply.h"
/**
 * 得到群信息的回复包，格式为：
 * 1. 头部
 * 2. 命令类型，1字节，得到群信息是0x4
 * 3. 回复码，1字节，成功是0x0
 * 4. 群内部ID，4字节
 * 5. 群外部ID，4字节
 * 6. 群类型，1字节
 * 7. 未知4字节
 * 8. 创建者QQ号，4字节
 * 9. 认证类型，1字节
 * 10. 未知的6字节，全0
 * 11. 群分类，2字节
 * 12. 未知的两字节，全0
 * 13. 群版本号, 4字节
 * 14. 群名称长度，1字节
 * 15. 群名称
 * 16. 未知的两字节，全0
 * 17. 群声明长度，1字节
 * 18. 群声明
 * 19. 群描述长度，1字节
 * 20. 群描述
 * 21. 群中成员的QQ号，4字节
 * 22. 成员分组, 1字节
 * 23. 成员类型, 1字节
 * 24. 如果存在更多成员，重复19, 20部分
 * 25. 尾部
 */
GetClusterInfoReplyPacket::GetClusterInfoReplyPacket(const uint8_t* buf, int len):
    ClusterOperateReply(buf, len, true)
{
    const uint8_t* cur = buf + QQ_HEADER_LENGTH_CLUSTER_IN;

    cur += readBufDw(clusterId, cur);
    cur += readBufDw(externalId, cur);
    cur += readBufB(clusterType, cur);
    cur += 4;
    cur += readBufDw(creator, cur);
    cur += readBufB(authType, cur);
    cur += 6;
    cur += readBufW(category, cur);
    cur += 2;
    cur += readBufDw(versionId, cur);

    uint8_t stringlen;
    cur += readBufB(stringlen, cur);
    clusterName.assign(cur, cur + stringlen);
    cur += stringlen;
    cur += 2;
    cur += readBufB(stringlen, cur);
    notice.assign(cur, cur + stringlen);
    cur += stringlen;
    cur += readBufB(stringlen, cur);
    describing.assign(cur, cur + stringlen);
    cur += stringlen;

    uint32_t memberUid;

    const uint8_t* max = buf + len;
    members.reserve((max - cur) / sizeof (uint32_t) + 1);

    while (cur < max) {
	cur += readBufDw(memberUid, cur);
	members.push_back(memberUid);
	cur += 2;
    }
    if (cur - buf > len)
	throw runtime_error("GetClusterInfoReplyPacket() Error: BUFFER len not enough");
}


